'use strict';

// Controller 对客户端发送的 event 进行处理；
const Controller = require('egg').Controller;

class DefaultController extends Controller {
  async ping () {
    const { ctx, app } = this;
    const message = ctx.args[0];
    await ctx.socket.emit('res', `Hi! I've got your message: ${message}`);
  }
  async server () {
    console.log('this is app io controller home server')
  }
  async namespaceTest () {
    const nsp = app.io.of('/test');
    nsp.on('connection', function (socket) {
      console.log('this namespace name is test')
      console.log('someone connected');
    });
    nsp.emit('hi', 'everyone!');
  }
}

module.exports = DefaultController;

